<extend name="Base/common" />
<block name="header">
    <header class="page-header bg-primary" id="overview">
        <div class="container-fluid text-left">
            <h2>用户登录</h2>
            <p class="lead"><span>还没有账号？</span><span><a href="{:U('User/register')}">立即注册</a></span></p>
        </div>
    </header>
</block>

<block name="body">
<section>
  <form class="form-horizontal login-form col-md-offset-4 col-md-4" action="__SELF__" method="post">
    <div class="form-group form-group-lg">
      <input type="text" class="form-control" id="inputEmail"  placeholder="用户名"  ajaxurl="/member/checkUserNameUnique.html" errormsg="请填写1-16位用户名" nullmsg="请填写用户名" datatype="*1-16" value="" name="username">
      <br/>
      <input type="password" class="form-control" id="inputPassword" placeholder="密码"  errormsg="密码为6-20位" nullmsg="请填写密码" datatype="*6-20" name="password">
      <br/>
      <input type="text" class="form-control" id="inputPassword" placeholder="验证码"  errormsg="请填写5位验证码" nullmsg="请填写验证码" datatype="*5-5" name="verify">
      <br/>
      <img class="verifyimg reloadverify" alt="点击切换" src="{:U('verify')}" style="cursor:pointer;">
      <br/>
      <span class="Validform_checktip text-danger"></span>
    </div>

    <div class="form-group form-group-lg text-center">
      <div class="checkbox">
        <label>
        <input type="checkbox"> 自动登录
        </label>
      </div>
      <br/>
      <button type="submit" class="btn btn-primary btn-lg col-sm-offset-4 col-sm-4">登 录</button>
    </div>
  </form>
</section>
</block>

<block name="side"> </block>
<block name="script">
	<script type="text/javascript">

    	$(document)
	    	.ajaxStart(function(){
	    		$("button:submit").addClass("log-in").attr("disabled", true);
	    	})
	    	.ajaxStop(function(){
	    		$("button:submit").removeClass("log-in").attr("disabled", false);
	    	});


    	$("form").submit(function(){
    		var self = $(this);
    		$.post(self.attr("action"), self.serialize(), success, "json");
    		return false;

    		function success(data){
    			if(data.status){
    				window.location.href = data.url;
    			} else {
    				self.find(".Validform_checktip").text(data.info);
    				//刷新验证码
    				$(".reloadverify").click();
    			}
    		}
    	});

		$(function(){
			var verifyimg = $(".verifyimg").attr("src");
            $(".reloadverify").click(function(){
                if( verifyimg.indexOf('?')>0){
                    $(".verifyimg").attr("src", verifyimg+'&random='+Math.random());
                }else{
                    $(".verifyimg").attr("src", verifyimg.replace(/\?.*$/,'')+'?'+Math.random());
                }
            });
		});
	</script>
</block>
